package com.eqdd.yiqidian.ui.gongneng.car;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.eqdd.yiqidian.R;
import com.eqdd.yiqidian.RecyclerViewCustom;
import com.eqdd.yiqidian.base.AppConstent;
import com.eqdd.yiqidian.base.Config;
import com.eqdd.yiqidian.bean.rebuild.CarUseInfoBean;
import com.eqdd.yiqidian.bean.rebuild.CarUseInfoBean;
import com.eqdd.yiqidian.bean.rebuild.ZhangPageResultBean;
import com.eqdd.yiqidian.bean.rebuild.slimedit.SlimEditEnterBean;
import com.eqdd.yiqidian.bean.rebuild.slimedit.SlimEditHintBean;
import com.eqdd.yiqidian.http.DialogCallBack;
import com.eqdd.yiqidian.http.HttpConfig;
import com.eqdd.yiqidian.http.HttpResult;
import com.eqdd.yiqidian.ui.base.SlimBaseMultiEditActivity;
import com.eqdd.yiqidian.ui.mine.UserCardActivity;
import com.eqdd.yiqidian.ui.mine.renwu.TextActivity;
import com.eqdd.yiqidian.ui.select.ShowRichTextActivity;
import com.eqdd.yiqidian.utils.RichTextUtil;
import com.eqdd.yiqidian.utils.ToastUtil;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;

import java.util.List;

/**
 * @author吕志豪 .
 * @date 17-11-20  上午11:36.
 * Github :https://github.com/lvzhihao100
 * E-Mail：1030753080@qq.com
 * 简书 :http://www.jianshu.com/u/6e525b929aac
 */

public class CarUseInfoActivity extends SlimBaseMultiEditActivity {

    private RecyclerViewCustom dataBinding;
    private Bundle bundle;
    private int id;
    private CarUseInfoBean infoBean;

    @Override
    public void initBinding() {
        /**
         * userGuid（创建人的guid），
         createrName（创建人的姓名），
         vehicleId：对应的车辆的id，
         plateNumber：车牌号，
         type：维修、保养或其他，
         agent：经办人
         */
        dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_recyclerview);
        initTopTitleBar(View.VISIBLE, "车辆使用详情");
    }


    @Override
    protected RecyclerView initRecyclerView() {
        return dataBinding.recyclerView;
    }

    @Override
    public void itemClick(int p) {
        switch (slimAdapterEx.getDataItem(p).getPosition()) {
            case 0:
                bundle = new Bundle();
                bundle.putString(Config.GUID, infoBean.getApplyer());
                startActivity(UserCardActivity.class, bundle);
                break;
            case 1:
                bundle = new Bundle();
                bundle.putInt(Config.ID, id);
                startActivity(CarInfoActivity.class, bundle);
                break;
            case 8:
                bundle = new Bundle();
                bundle.putString(Config.TITLE, "申请事由");
                bundle.putString(Config.CONTENT, infoBean.getTheReason());
                startActivity(TextActivity.class, bundle);
                break;
            case 17:
                bundle = new Bundle();
                bundle.putString(Config.TITLE, "备注");
                bundle.putSerializable(Config.RICH_TEXT_RESULT, RichTextUtil.getRichText("", infoBean.getPicAddr()));
                startActivityForResult(ShowRichTextActivity.class, bundle, Config.SELECT_RICH_TEXT);
                break;
        }
    }

    @Override
    protected void setEditBeans() {
        isSave = false;
        isRead = false;
        id = getIntent().getIntExtra(Config.ID, 0);
    }

    @Override
    protected void loadNetData() {
        OkGo.<HttpResult<CarUseInfoBean>>post(HttpConfig.BASE_URL + HttpConfig.CAR_USE_INFO)
                .params("comid", AppConstent.user.getCompanyId())
                .params("userGuid", AppConstent.user.getGuid())
                .params("recordId", id)
                .execute(new DialogCallBack<HttpResult<CarUseInfoBean>>(CarUseInfoActivity.this) {
                    @Override
                    public void onSuccess(Response<HttpResult<CarUseInfoBean>> response) {
                        HttpResult<CarUseInfoBean> httpResult = response.body();
                        ToastUtil.showShort(httpResult.getMsg());
                        if (httpResult.getStatus() == 200) {
                            infoBean = httpResult.getItems();
                            datas.add(new SlimEditEnterBean("申请人", infoBean.getApplyerName(), 0,true, ""));
                            datas.add(new SlimEditEnterBean("车辆", infoBean.getPlateNumber(), 1, true,""));
                            datas.add(new SlimEditHintBean("开始时间", infoBean.getStartTime(), 2));
                            datas.add(new SlimEditHintBean("结束时间", infoBean.getEndTime(), 3));
                            datas.add(new SlimEditHintBean("出发地", infoBean.getOrigin(), 4));
                            datas.add(new SlimEditHintBean("目的地", infoBean.getDestination(), 5));
                            datas.add(new SlimEditHintBean("司机姓名", infoBean.getTheDriverName(), 6));
                            datas.add(new SlimEditHintBean("坐车人数", infoBean.getPersonCount() + "个人", 7));
                            datas.add(new SlimEditEnterBean("申请事由", infoBean.getTheReason(), 8,true, ""));
                            datas.add(new SlimEditHintBean("关联客户", infoBean.getTheCustomer(), 9));
                            datas.add(new SlimEditHintBean("关联项目", infoBean.getTheProject(), 10));
                            datas.add(new SlimEditHintBean("还车时间", infoBean.getGivebackTime(), 11));
                            datas.add(new SlimEditHintBean("开始里程数", infoBean.getStartingMileage() + "km", 12));
                            datas.add(new SlimEditHintBean("结束里程数", infoBean.getEndingMileage() + "km", 13));
                            datas.add(new SlimEditHintBean("油费", infoBean.getFuelBills() + "元", 14));
                            datas.add(new SlimEditHintBean("过路费", infoBean.getRoadToll() + "元", 15));
                            datas.add(new SlimEditHintBean("收车人", infoBean.getSendee(), 16));
                            datas.add(new SlimEditEnterBean("备注", "", 17, true, ""));
                            slimAdapterEx.updateData(datas);
                        }
                    }
                });
    }
}
